class TankAi extends Tank {
	public team: Team = Team.Other;
	public constructor() {
		super();
	}
	actionFunc() {
		if (this.isDead) return;
		if (this.move(this.dir) == false || this.wantToChangeWay()) {
			this.changeWay();
		}
		if (this.wantToAttack()) {
			this.shoot();
		}
	}
	wantToAttack() {
		if (!this.canShoot) return;
		return Math.random() >= 0.9;
	}
	wantToChangeWay() {
		return Math.random() >= 0.9;
	}
	changeWay() {
		this.dir = Math.random() * 4 | 0;
	}
	private timer = new egret.Timer(1000, 0);
	$onAddToStage(stage: egret.Stage, nestLevel: number) {
		let data = this.getTankData();
		this.timer.delay = data.speed;
		this.timer.repeatCount = 0;
		this.timer.start();
		this.timer.addEventListener(egret.TimerEvent.TIMER, this.actionFunc, this);		
		super.$onAddToStage(stage, nestLevel)
	}
	$onRemoveFromStage() {
		this.timer.removeEventListener(egret.TimerEvent.TIMER, this.actionFunc, this);
		super.$onRemoveFromStage()
	}
}
